package com.project.platform.vo;

public class ResponseVO<T> {
    private int code;
    private String msg;
    private T data;

    public ResponseVO(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResponseVO<T> ok() {
        return new ResponseVO<>(200, "操作成功", null);
    }

    public static <T> ResponseVO<T> ok(T data) {
        return new ResponseVO<>(200, "操作成功", data);
    }

    // 兼容旧用法：data中放错误详情
    public static <T> ResponseVO<T> fail(int code, T data) {
        return new ResponseVO<>(code, "操作失败", data);
    }

    // 新用法：直接设置错误消息
    public static <T> ResponseVO<T> fail(int code, String msg) {
        return new ResponseVO<>(code, msg, null);
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
